﻿<?php
include("./config.php");
include("./utils.php");
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>列表显示</title>
  <?php include 'scripts-inc.php' ?>
  
  <script>


  var gStart=<?php echo getFromMap($_GET, 'start', 0); ?>;
  var gCount=<?php echo getFromMap($_GET, 'count', 0); ?>;
  var gName=<?php echo getFromMap($_GET, 'name', 0); ?>;
  $(function(){
    if(!gStart) gStart = 0;
    if(!gCount) gCount = 20;
    if(!gName) return;
    var u='query.php?op=by-name&start='+gStart+'&count='+gCount+'&name='+gName;
    $.ajax({url:u,
        dataType:"json",
        async:true,
        success : function(msg, textStatus) {
          var data_list = msg['by-name'];
          var count_list = msg['by-name-count'];
          var result = "";
          var template_item = hereDoc(item_template);
          var template_column = hereDoc(column_template);
          var COLUMN_COUNT = 6;
          var icol = 0;

            var data_size = data_list.length;
            var content = "";
            var count = 0;

            var count_map = {};
            for(var i in count_list){
              var count_data = count_list[i];
              var k = count_data.id;
              var v = count_data.count;
              count_map[k] = v;
            }

            for(var i in data_list){
              var data=data_list[i]; 
              data.i = count + 1;
              if (count_map[data.id]){
                data.count = count_map[data.id];
              }else{
                data.count = 0;
              }
              var s = nano(template_item, data);
              content += s;
              count += 1;
            }
            
            var next_start = gStart + gCount;
            var prev_start = gStart - gCount;
            if(prev_start < 0) prev_start = 0;
            var data={
              "start":gStart,
              "prev_start":prev_start,
              "next_start":next_start,
              "page":Math.floor(gStart/gCount)+1,
              "count":gCount, 
              "content":content
            };
            result += nano(template_column, data);
            icol += 1;
            if (icol == COLUMN_COUNT) {
              result += '<div class="clearfix"></div>';
              icol = 0;
            }


          $("#result").html(result);

        }
    },"text");
  });//end of $(function(){
  </script>
</head>
<body>

<div id="wrapper">
<div id="container">

<div id="nav_data_src">
  <?php include 'navbars-inc.php' ?>
</div>


<div class="clearfix"></div>
</div><!-- end of search-container -->

<div class="clearfix"></div>

<div id="content" class="col-xs-12 col-sm-7 col-md-7 col-lg-7" name="top">
  <div id="result">
    载入中...
  </div>
  
  <div class="clearfix"></div>
  <div class="text-right" id="mykeys" style="display: none">
    <a href="./index.php" class="" >
      <img src="./css/logo.png" style='max-width:22px;_width:expression(this.width > 22 ? "22px" : this.width);'/>范氏族谱
    </a>
    <a href="./index.php" class="" >http://mykeys.sinaapp.com/</a><br/>
    <span>微博账号(Ankiang)<img src="./css/logo-black.png" style='max-width:22px;_width:expression(this.width > 22 ? "22px" : this.width);'/></span><br/>
    <span><img src="./css/logo.png" style='max-width:22px;_width:expression(this.width > 22 ? "22px" : this.width);'/>范氏交流群(QQ: 530154123)</span>
  </div>
</div>

<div class="clearfix"></div>
<div id="hide-result"> </div>
<!-- .................................................... -->
</div><!-- end of container -->
</div><!-- end of wrapper -->
</body>
</html>
